var modalLock = false

export default {
    toast(msg) {
        msg = msg + ''
        return new Promise((resolve, reject) => {
            uni.showToast({
                icon: 'none',
                title: msg,
                duration: 3000,
                success: resolve,
                fail: reject
            });
        });
    },
    modal(msg) {
        return new Promise((resolve, reject) => {
            if(modalLock) return reject()
            modalLock = true
            let params;
            if(typeof msg === 'string') {
                params = {
                    content: msg,
                    showCancel: false
                };
            } else {
                params = {
                    showCancel: false,
                    ...msg
                }
            }
            uni.showModal(Object.assign({
                title: params.title || '',
                content: params.message,
                showCancel: params.showCancel,
                success: resolve,
                fail: reject,
                complete(){
                    modalLock = false
                }
            }, params));
        });
    }
}
